package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KCheckRule;
import com.ruoyi.qsng.service.IKCheckRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 打卡规则Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/rule")
@Api(tags = "pc--打卡规则Controller")
public class KCheckRuleController extends BaseController {
    @Autowired
    private IKCheckRuleService kCheckRuleService;

    /**
     * 查询打卡规则列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询打卡规则列表")
    public TableDataInfo list(KCheckRule kCheckRule) {
        startPage();
        List<KCheckRule> list = kCheckRuleService.selectKCheckRuleList(kCheckRule);
        return getDataTable(list);
    }

    /**
     * 导出打卡规则列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:export')")
    @Log(title = "打卡规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出打卡规则列表")
    public void export(HttpServletResponse response, KCheckRule kCheckRule) {
        List<KCheckRule> list = kCheckRuleService.selectKCheckRuleList(kCheckRule);
        ExcelUtil<KCheckRule> util = new ExcelUtil<KCheckRule>(KCheckRule.class);
        util.exportExcel(response, list, "打卡规则数据");
    }

    /**
     * 获取打卡规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取打卡规则详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kCheckRuleService.selectKCheckRuleById(id));
    }

    /**
     * 新增打卡规则
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:add')")
    @Log(title = "打卡规则", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增打卡规则")
    public AjaxResult add(@RequestBody KCheckRule kCheckRule) {
        return toAjax(kCheckRuleService.insertKCheckRule(kCheckRule));
    }

    /**
     * 修改打卡规则
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:edit')")
    @Log(title = "打卡规则", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改打卡规则")
    public AjaxResult edit(@RequestBody KCheckRule kCheckRule) {
        return toAjax(kCheckRuleService.updateKCheckRule(kCheckRule));
    }

    /**
     * 删除打卡规则
     */
    @PreAuthorize("@ss.hasPermi('qsng:rule:remove')")
    @Log(title = "打卡规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除打卡规则")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kCheckRuleService.deleteKCheckRuleByIds(ids));
    }
}
